package org.xsk.network.tcp.string;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * description: 服务器
 * <p>
 * date: 2021/6/10 11:22
 * author: x-one
 */
public class LoginServer {

    public static void main(String[] args) throws IOException {
        //建立连接
        ServerSocket server = new ServerSocket(8000);
        Socket socket = server.accept();

        //打开输入流
        InputStream is = socket.getInputStream();
        //读
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String info=null;
        while((info=br.readLine())!=null) {
            System.out.println("我是服务器，客户端说："+info);
        }

        String reply ="我是服务器，欢迎登陆";
        OutputStream os=socket.getOutputStream();
        os.write(reply.getBytes());

        //关闭资源
        os.close();
        br.close();
        is.close();
        socket.close();
        server.close();
    }
}
